import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.jdom.Document;
import org.jdom.Element;
import org.jdom.input.SAXBuilder;
import org.jdom.output.XMLOutputter;


public class ConversorSVG {

	public static void convert(String fileNameIn, String fileNameOut){
		SAXBuilder builder = new SAXBuilder();
		Iterator itr, itr2;
		String viewBoxX,viewBoxY;
		try {
			Document doc = builder.build(fileNameIn);
			Element root = doc.getRootElement();
			
			viewBoxX = root.getAttributeValue("viewBox").split(" ")[0];
			viewBoxY = root.getAttributeValue("viewBox").split(" ")[1];
			
			List gTags = root.getChildren();
			itr = gTags.iterator();			
			while (itr.hasNext()) {
				Element gElement = (Element) itr.next();
				gElement.setAttribute("transform", "translate(" + viewBoxX + "," + viewBoxY +")" );
				List paths = gElement.getChildren();
				List pathsData = new ArrayList();
				itr2 = paths.iterator();
				while (itr2.hasNext()){
					Element pathElement = (Element) itr2.next();
					pathElement.setText(pathElement.getAttribute("bairro").getValue());
					//Element pathData = new Element("text");
					//pathData.setName("text");
					//pathData.setText(pathElement.getAttribute("bairro").getValue());
					//pathsData.add(pathData);
					System.out.println(pathElement.getAttribute("bairro").getValue());
				}
				//paths.addAll(pathsData);
			}
		    XMLOutputter outp = new XMLOutputter();
		    outp.output(doc,new FileOutputStream(fileNameOut));

		} catch (Exception e){
			e.printStackTrace();
		}
	}
}
	
